package com.jp.knowledge.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;

import com.jp.knowledge.R;

/**
 * Created by 528787067@qq.com on 2017/2/2.
 */

public class ExperienceSubDialog extends Dialog {

    private int parentPosition;
    private String groupId;

    public ExperienceSubDialog(Context context) {
        super(context, R.style.experience_sub_dialog);
        int dialogWidth = View.MeasureSpec.makeMeasureSpec(
                (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.95 + 0.5),
                View.MeasureSpec.UNSPECIFIED);
        int dialogHeight = View.MeasureSpec.makeMeasureSpec(
                (int) (getContext().getResources().getDisplayMetrics().heightPixels * 0.60 + 0.5),
                View.MeasureSpec.UNSPECIFIED);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.windowAnimations = R.style.experience_sub_dialog_anim;
        layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
        layoutParams.width = dialogWidth;
        layoutParams.height = dialogHeight;
    }

    public void setParentPosition(int parentPosition){
        this.parentPosition = parentPosition;
    }

    public int getParentPosition(){
        return this.parentPosition;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN && this.dialogActionDownListener != null) {
            this.dialogActionDownListener.onDialogActionDown(event.getX(), event.getY());
            return true;
        } else{
            return super.onTouchEvent(event);
        }
    }

    @Override
    public void dismiss() {
        if(this.dialogDismissListener != null)
            this.dialogDismissListener.onDismiss();
        super.dismiss();
    }

    /* 对话框关闭监听 */
    private DialogDismissListener dialogDismissListener;
    public void setDialogDismissListener(DialogDismissListener dialogDismissListener){
        this.dialogDismissListener = dialogDismissListener;
    }
    public interface DialogDismissListener{
        void onDismiss();
    }

    /* 对话框触摸监听 */
    private DialogActionDownListener dialogActionDownListener;
    public void setDialogActionDownListener(DialogActionDownListener dialogActionDownListener){
        this.dialogActionDownListener = dialogActionDownListener;
    }
    public interface DialogActionDownListener{
        void onDialogActionDown(float x, float y);
    }
}
